{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">栏目管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <blockquote class="layui-elem-quote">1、添加、修改和删除栏目全部完成后，请点击【更新栏目缓存】；2、筛选时，点击搜索后如果显示无数据，再点击一次搜索试试；</blockquote>
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
        </div>
    </div>
</div>
<script type="text/html" id="barTool">
    <a data-open="{{d.add_url}}" data-width="900px" data-height="600px" class="layui-btn layui-btn-xs layui-btn-normal" title="添加子栏目">添加子栏目</a>
    <a data-open='{:url("edit")}?id={{ d.id }}' data-width="900px" data-height="600px" class="layui-btn layui-btn-xs" title="编辑">编辑</a>
    <a href='{:url("del")}?ids={{ d.id }}' class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" data-href="{:url('multi')}?id={{d.id}}&param=status" value="{{d.id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>
{/block}
{block name="script"}
<script>
    layui.use('yznTable', function() {
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            delete_url: "{:url('del')}",
            modify_url: '{:url("multi")}',
        };

        table.render({
            init: init,
            id: 'currentTable',
            elem: '#currentTable',
            toolbar: ['refresh',
                [{
                    text: '新增栏目',
                    url: "{:url('add')}",
                    method: 'open',
                    class: 'layui-btn layui-btn-sm layui-btn-normal',
                    icon: 'iconfont icon-add',
                    extend: 'data-width="900px" data-height="600px"',
                },
                    {
                        text: '新增单页',
                        url: "{:url('singlepage')}",
                        method: 'open',
                        class: 'layui-btn layui-btn-sm layui-btn-normal',
                        icon: 'iconfont icon-add',
                        extend: 'data-width="900px" data-height="600px"',
                    }
                ], 'delete', [{
                    text: '栏目授权',
                    url: "{:url('cat_priv')}",
                    method: 'open',
                    class: 'layui-btn layui-btn-sm layui-btn-normal',
                    icon: 'iconfont icon-other',
                },
                    {
                        text: '栏目数据校正',
                        url: "{:url('count_items')}",
                        method: 'request',
                        class: 'layui-btn layui-btn-sm',
                        icon:'iconfont icon-right',
                        extend: 'data-table="currentTable"',
                    },
                    {
                        text: "更新栏目缓存",
                        url: "{:url('public_cache')}",
                        method: 'request',
                        class: 'layui-btn layui-btn-sm',
                        icon:'iconfont icon-shuaxin1',
                        extend: 'data-table="currentTable"',
                    }]
            ],
            url: '{:url("index")}',
            search:true,
            cols: [
                [
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'listorder', width: 70, title: '排序', edit: 'text' ,search:false, align: "center"},
                    { field: 'id', width: 70, title: 'ID',search:false , align: "center" ,search:false},
                    { field: 'sites', width: 200, title: '所属站点', align: "center" },
                    { field: 'catname',align: "left", title: '栏目名称' },
                    { field: 'items', width: 80, title: '数据量',search:false, align: "center" },
                    { field: 'catdir', width: 120, title: '唯一标识' },
                    { field: 'type', width: 100, title: '栏目类型', templet: '<div>{{#  if(d.type==1){ }} 单页 {{#  } else if(d.type==2){  }} 列表 {{#  }  else { }} 未知 {{#  } }}</div>' },
                    { field: 'modelname', width: 120, title: '所属模型' },
                    { field: 'url', width: 60, align: "center", title: 'URL', templet: table.url,search:false },
                    { field: 'status', width: 100, align: "center", title: '状态', templet: '#statusTpl', unresize: true,search:false },
                    { fixed: 'right', width: 210, title: '操作', toolbar: '#barTool', align: "center" }
                ]
            ],
        });
    });
</script>
{/block}